
import { defineStore } from 'pinia';
// if (import.meta.hot) {
//   import.meta.hot.accept(acceptHMRUpdate(useCounterStore, import.meta.hot));
// }
export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
  }),
  actions: {
    increment() {
      this.count++;
    },
    decrement() {
      this.count--;
    },
    async fetchInitialCount() {
      const response = await fetch('https://api.example.com/count');
      const data = await response.json();
      this.count = data.count;
    },
  },
  getters: {
    doubleCount: (state) => state.count * 2,
  },
});
// 确保 HMR 代码在 store 定义之后执行，并且只在开发环境中启用
if (import.meta.hot) {
  import.meta.hot.accept(({ useCounterStore }) => {
    useCounterStore().$reset();
  });
}